/*************************************************************************
	> File Name: hzoj_636.cpp
	> Author: 
	> Mail: 
	> Created Time: Sun 18 Aug 2024 05:54:15 PM CST
 ************************************************************************/

#include<iostream>
#include <vector>
#include <queue>
using namespace std;
#define MAX_N 100000
int in_deg[MAX_N + 5];
int ans[MAX_N + 5];
vector<vector<int>> g(MAX_N + 5);

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 0, x, y; i < m; i++) {
		scanf("%d%d", &x, &y);
		in_deg[y] += 1;
		g[x].push_back(y);
	}
	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(in_deg[i]) continue;
		q.push(i);
		ans[i] = 1;
	}
	while (!q.empty()) {
		int now = q.front();
		q.pop();
		for(int i = 0, I = g[now].size(); i < I; i++) {
			int temp = g[now][i];
			in_deg[temp] -= 1;
			if(in_deg[temp] == 0) q.push(temp);
			ans[temp] = max(ans[now] + 1, ans[temp]);
		}
	}
	for(int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}
